/*
 * this class content Main menthod
 * show the menu for the use to choose
 * try cacth the exception
 */


/**
 *
 * @author luan
 */

import java.util.Scanner;
public class BankTest {
    //=======================
    //Main method to run the program
    //========================
    public static void main(String agrs[])
    {
        int choose=0;
        Bank bank=new Bank();
        Scanner sc=new Scanner(System.in);
        try
        {
            while(true)
            {
                System.out.println("1/Create a new account");
                System.out.println("2/Withdraw Cash");
                System.out.println("3/Deposit cash");
                System.out.println("4/Display account details");
                System.out.println("5/Exit");
                System.out.println("\n\nYour choose: ");
                try{
                choose=sc.nextInt();
                }
                catch(Exception ex)
                {
                    System.out.println("Wrong key in must be a numberic.....");
                    System.exit(1);
                }
                switch(choose)
                {
                    case 1:
                    {   double bal=0;
                         System.out.println("Input First name:");
                         String fName=sc.next();
                         System.out.println("Input Last name: ");
                         String lName=sc.next();
                         try{
                         System.out.println("Input Balance: ");
                         bal=sc.nextDouble();
                         }
                         catch(Exception ex)
                         {
                            System.out.println("Wrong key in must be numberic....");
                            System.exit(1);
                         }
                         if(bal<0)
                             throw new Exception("Balance can not less than 0");
                         else{
                         Account acc=new Account(bank.lastAccountNumber,fName,lName,bal);
                         bank.createAccount(acc);
                         break;
                         }
                    }
                    case 2: bank.withdraw();break;
                    case 3: bank.deposit();break;
                    case 4: bank.display();break;
                    case 5:
                    {
                        System.out.println("Program already exited");
                        System.exit(1);
                    }
                    default:
                    {
                        System.out.println("Wrong Choosen");
                        break;
                    }
                }
            }
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
    }
}
